/**
	@file bootloader.S
	@author Andrew D. Zonenberg
	@brief Just a jumping point for the main function
 */

.set noreorder					/*	Prevent any optimizations from reordering instructions!
									We want exe to exactly match source! */

/*
	Program entry point
 */
.section .startup.bootvec, "ax", @progbits 
.globl _start
_start:
	/* TODO: copy initialized data from the end of the ROM image into RAM */
	
	/*	Make sure we have a valid stack pointer. Just stick it near the end of ram for now.
		Restriction - must be uncached since cache miss handling isn't implemented in the CPU as of r120.
		Current RAM is a000:0000 to a000:1fff
		*/
	lui		$sp, 0xa000
	addiu	$sp, 0x1ffc
	
	/* Call the main function */
	j		main
	nop
	
	/* should never get here, but if we do, infinite loop */
.infloop:
	j		.infloop

	/* padding */
	nop
	nop
	nop
	nop

/*
	CP0 timer function
 */
.section .startup
.global cp0_timer_init
cp0_timer_init:
	mtc0	$zero, $9		/* start counting now */
	jr		$ra
	nop
	nop

.section .startup
.global cp0_timer_value
cp0_timer_value:
	mfc0	$v0, $9
	jr		$ra
	nop
	nop
